//
//  PAMainViewController.swift
//  PersonalApp
//
//  Created by yuchanglin on 2017/12/7.
//  Copyright © 2017年 yuchanglin. All rights reserved.
//

import UIKit

class PAMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupControllers()
    }

    private func setupControllers()->(){
        let home = PAHomeViewController()
        addChildController(home, imageName: "TabPerson", selectImageName: "TabPersonClick", title: "首页")
        let profie = PAProfieViewController()
        addChildController(profie, imageName: "TabPurchase", selectImageName: "TabPurchaseClick", title: "个人")
    }
}
// MARK: - 设置界面
extension PAMainViewController{
    private func addChildController(_ controller:UIViewController,imageName:String?,selectImageName:String?,title:String?)->(){
        
        guard let title = title,
              let imageName = imageName,
              let selectImageName = selectImageName else {
            return
        }
        controller.title = title
        controller.tabBarItem.selectedImage = UIImage.init(named: selectImageName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        controller.tabBarItem.image = UIImage.init(named: imageName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        //设置选中时文字样式
    controller.tabBarItem.setTitleTextAttributes([NSAttributedStringKey.foregroundColor:UIColor.init(red: 20/255, green: 151/255, blue: 232/255, alpha: 1)], for: .selected)
        
        let mainNavi = PANavigationBarController.init(rootViewController: controller)
        addChildViewController(mainNavi)
    }
}
